﻿using System;
using System.Windows.Input;

namespace Foundation
{
    public class CommandBinding
    {
        public CommandBinding(ICommand command)
        {
            Command = command;
        }

        public ICommand Command { get; private set; }
        public event EventHandler<ExecutedEventArgs> Executed = (sender, args) => { };
        public event EventHandler<CanExecuteEventArgs> CanExecute = (sender, args) => { };      
        public event EventHandler<ExecutedEventArgs> PreviewExecuted = (sender, args) => { };
        public event EventHandler<CanExecuteEventArgs> PreviewCanExecute = (sender, args) => { };

        internal void OnExecuted(object sender, ExecutedEventArgs args)
        {
            Executed(sender, args);
        }

        internal void OnCanExecute(object sender, CanExecuteEventArgs args)
        {
            CanExecute(sender, args);
        }

        internal void OnPreviewExecuted(object sender, ExecutedEventArgs args)
        {
            PreviewExecuted(sender, args);
        }

        internal void OnPreviewCanExecute(object sender, CanExecuteEventArgs args)
        {
            PreviewCanExecute(sender, args);
        }
    }

    public class ExecutedEventArgs : EventArgs
    {
        public ExecutedEventArgs(ICommand command, object parameter)
        {
            Command = command;
            Parameter = parameter;
        }

        public ICommand Command { get; private set; }
        public object Parameter { get; private set; }
    }

    public class CanExecuteEventArgs : EventArgs
    {
        public CanExecuteEventArgs(ICommand command, object parameter)
        {
            Command = command;
            Parameter = parameter;
            CanExecute = true;
        }

        public ICommand Command { get; private set; }
        public object Parameter { get; private set; }
        public bool CanExecute { get;  set; }
    }
}